//
//  LFTabBarViewController.m
//  LocalLife
//
//  Created by 李立达 on 15/11/21.
//  Copyright © 2015年 heima11. All rights reserved.
//

#import "LFTabBarViewController.h"
#import "LFfactoy.h"
@interface LFTabBarViewController ()
@property (strong, nonatomic) UIView* topView;
@property (strong, nonatomic) UIView* bottmView;
@end

@implementation LFTabBarViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    _bottmView = [[UIView alloc] initWithFrame:CGRectMake(0, KscreedHeight - KtabBarHeight, KscreedWdith, KtabBarHeight)];
//
//    _bottmView.backgroundColor = [UIColor redColor];
//    self.tabBar.hidden=YES;
    
//    _bottmView =[[UIView alloc]initWithFrame:self.tabBar.bounds];
    
    [self.view addSubview:_bottmView];

    for (int i = 0; i < 5; i++) {

        NSString* btnimage = [NSString stringWithFormat:@"home_%d", i];
        NSString* btnselect = [NSString stringWithFormat:@"home_%d_pressed", i];
        UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setBackgroundImage:[UIImage imageNamed:btnimage] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:btnselect] forState:UIControlStateSelected];
        [btn setFrame:CGRectMake(i * (KscreedWdith * 0.2), 0, (KscreedWdith * 0.2), KtabBarHeight)];
        btn.tag = i;
        [btn addTarget:self action:@selector(ChangeVc:) forControlEvents:UIControlEventTouchUpInside];
        if (i == 0) {
            btn.selected = YES;
        }
        if (i == 0) {
            btn.selected = YES;
        }

        [self.bottmView addSubview:btn];
    }

    //设置更多view

    _topView = [[UIView alloc] initWithFrame:CGRectMake(0, KscreedHeight - KtabBarHeight * 2, KscreedWdith, KtabBarHeight)];

    _topView.backgroundColor = [UIColor whiteColor];

    //设置更多弹出的view背景图片
    UIImageView* topimage = [[UIImageView alloc] init];

    [topimage setFrame:_topView.bounds];
    topimage.image = [UIImage imageNamed:@"home_topbar"];
    topimage.userInteractionEnabled = YES;
    [_topView addSubview:topimage];

    //  添加联系商家按钮
    UIButton* xmpp = [UIButton buttonWithType:UIButtonTypeCustom];
    [xmpp setFrame:CGRectMake(0, 0, KscreedWdith * (90.0 / 375.0), KtabBarHeight)];
    [xmpp setTitle:@"联系我们" forState:UIControlStateNormal];
    [xmpp addTarget:self action:@selector(ChangeVc:) forControlEvents:UIControlEventTouchUpInside];
    xmpp.tag = 5;
    [_topView addSubview:xmpp];
    //摇一摇
    UIButton* shake = [LFfactoy buttonWithFrame:CGRectMake(xmpp.frame.size.width, 0, KscreedWdith * (110.0 / 375.0), KtabBarHeight) WithTitle:@"摇一摇" WithAction:@selector(ChangeVc:) WithTarget:self];
    shake.tag = 6;
    [_topView addSubview:shake];
    //zhibo
    UIButton* Onlive = [LFfactoy buttonWithFrame:CGRectMake(KscreedWdith * (200.0 / 375.0), 0, KscreedWdith * (80.0 / 375.0), KtabBarHeight) WithTitle:@"直播" WithAction:@selector(ChangeVc:) WithTarget:self];
    Onlive.tag = 7;
    [_topView addSubview:Onlive];
    //关于
    UIButton* about = [LFfactoy buttonWithFrame:CGRectMake(KscreedWdith * (280.0 / 375.0), 0, KscreedWdith * (70.0 / 375.0), KtabBarHeight) WithTitle:@"关于" WithAction:@selector(ChangeVc:) WithTarget:self];
    about.tag = 8;
    [self.topView addSubview:about];
    [self.view addSubview:_topView];
    _topView.hidden = YES;
}

- (void)ChangeVc:(UIButton*)btn
{

    _topView.hidden = YES;
    [_bottmView.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        UIButton *btn=obj;
        btn.selected=NO;
    }];
    btn.selected = YES;

    if (btn.tag == 4) {
        _topView.hidden = NO;
        return;
    }
    if (btn.tag < 4) {
        self.selectedIndex = btn.tag;
    }
    else {
        self.selectedIndex = btn.tag - 1;
    }
}
-(void)showHiddenbottmView:(BOOL)flag
{
    if (flag) {
        _topView.hidden = YES;
        _bottmView.hidden = YES;
    }
    else {
        _bottmView.hidden = NO;
    }
}
@end
